package com.jrtc.backend.controller;

import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.base.entity.bo.CatchBallRecord;
import com.jrtc.base.entity.bo.QuestionNaireDepartment;
import com.jrtc.base.entity.vo.CatchBallRecordVo;
import com.jrtc.service.CatchBallRecordService;
import com.jrtc.service.QuestionNaireDepartmentService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.swing.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("naireDepartmentController")
public class QuestionNaireDepartmentController {
    /**
     * 服务对象
     */
    @Resource
    private QuestionNaireDepartmentService questionNaireDepartmentService;

    /**
     * id获取问卷分类信息
     * */
    @PostMapping("/classification")
    public ResultDTO classification(@RequestBody Map<String, Object> map){
        Integer id = 0;
        if (map.get("id") != null && !map.get("id").equals("")){
            id = Integer.parseInt(map.get("id").toString());
        }

        List<QuestionNaireDepartment> questionNaireDepartmentList = questionNaireDepartmentService.classification(id);
        return ResultDTOBuilder.success(questionNaireDepartmentList);
    }

    /**
     * 医生添加问卷分类
     * */
    @PostMapping("/insertClassification")
    public ResultDTO insertClassification(HttpServletRequest request, @RequestBody QuestionNaireDepartment questionNaireDepartment){
        int i;
        try {
            i = questionNaireDepartmentService.insertClassification(request, questionNaireDepartment);
        } catch (Exception e){
            return ResultDTOBuilder.failureMsg(e.getMessage());
        }

        if (i > 0){
            return ResultDTOBuilder.success("添加成功");
        }
        else {
            return ResultDTOBuilder.failureMsg("添加失败");
        }
    }
}